<?php
namespace Home\Controller;
use Think\Controller;

class LoanIndexController extends CommonController {

  /*
   * 用户姓名
   */
  public function getUser_username(){
      $get = I('data');
      $get = $this->jiemi($get);
      if (empty($get['user_id'])){
          $data['ret'] = '1002';
          $data['code'] = '请先登录，';
          $data1 = $this->jiami($data);
          $this->return = ['data' => $data1];
          return false;
      }
      //$get['user_id']=501;
      $user_chatid=M('user','','DB2')->where(['id'=>$get['user_id'],'is_delete'=>1])->field('username')->find();
      $user_alipay_bind=M('user_alipay_bind','','DB2')->where(['user_id'=>$get['user_id'],'status'=>1])->field('account')->find();
      $user_chatid['alipay_account']=empty($user_alipay_bind)?'':$user_alipay_bind['account'];
      $user_chatid['username']=empty($user_chatid['username'])?'':$user_chatid['username'];
      if($user_chatid){
          $data['ret'] = '1001';
          $data['code'] = 'success';
          $data['data']=$user_chatid;
          $data = $this->jiami($data);
          $this->return = ['data' => $data];
          return true;
      }else{
          $data['ret'] = '1002';
          $data['code'] = '数据异常，';
          $data1 = $this->jiami($data);
          $this->return = ['data' => $data1];
          return false;
      }
  }
    /*
     * 首页额度接口
     */
    public function index_amount(){
        header("Access-Control-Allow-Origin: *");
        $get = I('data');
        $get = $this->jiemi($get);
        //$get['user_id']=4202;
//        if (empty($get['user_id'])){
//            $data['ret']='1002';
//            $data['code']='请先登录';
//            $data = $this->jiami($data);
//            $this->return = ['data'=>$data];
//            return false;
//        }
        //$get['user_id']=501;
        $user=M('user','','DB2')->where(['id'=>$get['user_id'],'is_delete'=>1])->field('balance,quota,cert_status,chat_id')->find();
        $shopkeeper=M('communication','','DB2')->where(['shop_id'=>$user['chat_id'],'status'=>1])->field('account,nickname')->find();

        $v2_loan=M('vz_loan','','DB2')->where(['user_id'=>$get['user_id'],'status'=>1])->field('order_number,atlast_time,loan_amount')->find();
        if($user['cert_status']!=2){
            $user['balance']='10000';
            $user['quota']='10000';
        }
        $user['balance']=empty($user['balance'])?'0':$user['balance'];
        $user['quota']=empty($user['quota'])?'0':$user['quota'];
        switch ($user['cert_status']){
            case 1:$user['title_status']='未认证';
                break;
            case 2:$user['title_status']='去借款';
                break;
            case 3:$user['title_status']='审核未通过';
                break;
            case 4:$user['title_status']='其他认证中';
                break;
            case 5:$user['title_status']='信息审核中';
                break;
            case 6:$user['title_status']='信息审核中';
                break;
            default :$user['title_status']='信息审核中';
        }
        $user['account']=$shopkeeper['account'];//客服账号
        $user['nickname']=$shopkeeper['nickname'];//客服昵称
        //print_r($user);die;
        if($user){
            $user['loan_list']=empty($v2_loan)?' ':$v2_loan;
            $data['ret']='1001';
            $data['code']='success';
            $data['data']=$user;
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return true;
        }else{
            $data['ret']='1002';
            $data['code']='数据异常';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
    }
    /*
     *借款记录列表
     */
    public function loan_list(){
        header("Access-Control-Allow-Origin: *");
        $get = I('data');
        $get = $this->jiemi($get);
        //$get['user_id']=4202;
        if (empty($get['user_id'])){
            $data['ret']='1002';
            $data['code']='请先登录';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        $page=empty($get['page'])?0:$get['page'];//0条开始
        $lime=empty($get['lime'])?7:$get['lime'];//一页几条
        //$get['user_id']=1;
        //,'status'=>['in','1,3,4,5']
        $v2_loan=M('vz_loan','','DB2')->where(['user_id'=>$get['user_id'],'status'=>['lt',6]])->limit($page,$lime)->order('ctime desc')->field('order_number,atlast_time,loan_amount,status,overdue_money,repay_order')->select();
        //print_r($v2_loan);die;
        foreach ($v2_loan as $key=>$value){
            $v2_loan[$key]['atlast_time']=date('Y-m-d',$value['atlast_time']);
            switch ($value['status']){
                case 0:$v2_loan[$key]['status_title']='待审核';
                    break;
                case 1:$v2_loan[$key]['status_title']='已借款';
                    break;
                case 2:$v2_loan[$key]['status_title']='已还款';
                    break;
                case 3:$v2_loan[$key]['status_title']='已逾期';
                    $v2_loan[$key]['loan_amount']+=$value['overdue_money'];
                    break;
                case 4:$v2_loan[$key]['status_title']='被拒绝';
                    break;
                case 5:$v2_loan[$key]['status_title']='待打款';
                    break;
            }
        }
            //$user['loan_list']=empty($v2_loan)?' ':$v2_loan;
            $data['ret']='1001';
            $data['code']='success';
            $data['is_null']=empty($v2_loan)?1:0;//0有数据1没数据
            $data['page']=count($v2_loan)+$page;
            $data['data']=$v2_loan;
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return true;
    }
    /*
     * 借款页面数据
     */
    public function loan_index_data(){
        header("Access-Control-Allow-Origin: *");
        $get = I('data');
        $get = $this->jiemi($get);
        //$get['user_id']=886;
        if (empty($get['user_id'])){
            $data['ret']='1002';
            $data['code']='请先登录';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        $balance=M('user','','DB2')->where(['id'=>$get['user_id']])->field('balance,shop_identifier')->find();
        $user['available_amount']=$balance['balance'];//剩余可用余额
        $param_id=M('merchant_param_record','','DB2')->where(['shop_identifier'=>$balance['shop_identifier']])->order('id desc')->field('day_interest,borrowing_cycle')->find();

        $timee=86400*$param_id['borrowing_cycle'];//7天
        $user['atlast_time']=date('Y-m-d',time()+$timee);
        $loan_type=[
            ['type'=>'1','title'=>'日常消费'],
            ['type'=>'2','title'=>'医疗'],
            ['type'=>'3','title'=>'旅游'],
            ['type'=>'4','title'=>'装修'],
            ['type'=>'5','title'=>'教育']
        ];
        $user['loan_type']=$loan_type;
        $user['shop_identifier']=$balance['shop_identifier'];
        $data['ret']='1001';
        $data['code']='success';
        $data['data']=$user;
        $data = $this->jiami($data);
        $this->return = ['data'=>$data];
        return true;
    }
    /*
     * 我的页面功能列表
     */
    public function my_index_list(){
        $list=[
            ['url'=>'http://xych.xycpro.com/Dev/v2#/authentication','type'=>2,'logo'=>'http://xycha.oss-cn-hangzhou.aliyuncs.com/xycha/identify.png','title'=>'信用认证'],
            ['url'=>'http://xych.xycpro.com/Dev/v2#/BindZfb','type'=>2,'logo'=>'http://xycha.oss-cn-hangzhou.aliyuncs.com/xycha/alipay.png','title'=>'绑定支付宝'],
            ['url'=>'','type'=>1,'logo'=>'http://xycha.oss-cn-hangzhou.aliyuncs.com/xycha/safe.png','title'=>'安全设置'],
            ['url'=>'','type'=>1,'logo'=>'http://xycha.oss-cn-hangzhou.aliyuncs.com/xycha/help.png','title'=>'帮助反馈']
//            ['url'=>'','type'=>1,'logo'=>'www.baidu.com','title'=>'退出登录']
        ];
        $data['ret']='1001';
        $data['code']='success';
        $data['data']=$list;
        $data = $this->jiami($data);
        $this->return = ['data'=>$data];
        return true;
    }
    /*
     * 借款协议
     */
    public function loan_agreement(){
        $this->display();
    }
    /*
     * 申请接口接口
     */
    public function application_loan(){
        header("Access-Control-Allow-Origin: *");
        $get = I('data');
        $get = $this->jiemi($get);
//        $get['user_id']=24069;
//            $get['loan_amount']=1;
//        $get['loan_type']=1;
//        $get['shop_identifier']='0100030043';
        if (empty($get['user_id'])){
            $data['ret']='1002';
            $data['code']='请先登录';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        if(empty($get['loan_amount'])){
            $data['ret']='1002';
            $data['code']='借款金额不能为空';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        if(empty($get['loan_type'])){
            $data['ret']='1002';
            $data['code']='请选择借款用途';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        if(empty($get['shop_identifier'])){
            $data['ret']='1002';
            $data['code']='商户号为空';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        if(!is_int((int)$get['loan_amount'])){
            $data['ret']='1002';
            $data['code']='借款金额不是整数';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
//        $get['user_id']=1;
//        $get['loan_amount']=1500;
        $user=M('user','','DB2')->where(['id'=>$get['user_id']])->field('balance,channel,status')->find();
        if($user['status']!=1){
            $data['ret']='1002';
            $data['code']='账号已限制借款';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        if($user['balance']<$get['loan_amount']){
            $data['ret']='1002';
            $data['code']='借款金额不能大于剩余额度';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        $merchant_param_record=M('merchant_param_record','','DB2')->where(['shop_identifier'=>$get['shop_identifier']])->order('id desc')->field('id,borrowing_cycle,font_interest,day_interest')->find();
        if($merchant_param_record['font_interest']>0){
            $data7['fee']=$get['loan_amount']*($merchant_param_record['font_interest']/100);//手续费 砍头息
        }
        if($merchant_param_record['day_interest']>0) {
            $data7['day_interest_money'] = $get['loan_amount'] * ($merchant_param_record['day_interest'] / 10000);
        }
        $data7['user_id']=$get['user_id'];//用户id
        $data7['loan_amount']=$get['loan_amount'];//借款金额
        $data7['order_number']=$this->_getworderno('J');//借款订单号
        $data7['repay_order']=$this->_getworderno('H');//还款订单号
        $data7['status']=0;//0待审核1未还款2已还款3已逾期
        $timee7=86400*$merchant_param_record['borrowing_cycle'];
        $data7['atlast_time']=strtotime('today')+$timee7;
        $data7['ctime']=time();//创建时间
        $data7['utime']=$data7['ctime'];//修改时间
        $data7['loan_type']=$get['loan_type'];//借款用途
        $data7['shop_identifier']=$get['shop_identifier'];//商户号
        $data7['loan_time']=time();//借款时间
        //$shop_identifier=$get['shop_identifier'];//商户号
        $data7['param_id']=$merchant_param_record['id'];//修改时间
        //print_r($data7);die;
        /*
          * 按顺序分配出借人
            */
        $channel=M('channel','','DB2')->where(['chan_id'=>$user['channel'],'shop_identifier'=>$get['shop_identifier']])->field('lender_id')->find();
        $lender=M('lender','','DB2')->where(['id'=>$channel['lender_id'],'is_delete'=>1,'shop_idenfier'=>$get['shop_identifier']])->getField('id');
        if($channel&&$lender){
            $data7['lender_id']=M('lender','','DB2')->where(['id'=>$channel['lender_id'],'is_delete'=>1])->getField('id');
        }else{
            $lender_id=M('lender','','DB2')->where(['shop_idenfier'=>$get['shop_identifier'],'is_delete'=>1])->getField('id');
            $lender_id_desc=M('lender','','DB2')->where(['shop_idenfier'=>$get['shop_identifier'],'is_delete'=>1])->order('id desc')->getField('id');
            $lender_distribution=M('lender_distribution','','DB2')->where(['shop_identifier'=>$get['shop_identifier']])->order('id desc')->getField('lender_id');
            if(empty($lender_distribution)){
                $data7['lender_id']=M('lender','','DB2')->where(['id'=>$lender_id])->getField('id');
            }else{
                if($lender_distribution<$lender_id_desc){
                    $data7['lender_id']=M('lender','','DB2')->where(['id'=>['gt',$lender_id_desc],'shop_idenfier'=>$get['shop_identifier']])->getField('id');
                }elseif($lender_distribution==$lender_id_desc){
                    $data7['lender_id']=M('lender','','DB2')->where(['id'=>['eq',$lender_id_desc]])->getField('id');
                }else{
                    $data7['lender_id']=M('lender','','DB2')->where(['id'=>$lender_id])->getField('id');
                }
            }
        }
        if(empty($data7['lender_id'])){
            $data['ret']='1002';
            $data['code']='暂无出借人，';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        /*
        * 按顺序分配出借人
        */
        M('lender_distribution','','DB2')->startTrans();
        M('vz_loan','','DB2')->startTrans();
        M('user','','DB2')->startTrans();
        $vz_loan=M('vz_loan','','DB2')->add($data7);
        $data77['user_id']=$get['user_id'];//用户id
        $data77['shop_identifier']=$get['shop_identifier'];//商户号
        $data77['lender_id']=$data7['lender_id'];//出借人id
        $data77['ctime']=time();//时间
        $lender_distribution=M('lender_distribution','','DB2')->add($data77);
        $balance_update=$user['balance']-$get['loan_amount'];
        $user_balance=M('user','','DB2')->where(['id'=>$get['user_id']])->save(['balance'=>$balance_update]);
        if($vz_loan&&$user_balance&&$lender_distribution){
            M('vz_loan','','DB2')->commit();
            M('user','','DB2')->commit();
            M('lender_distribution','','DB2')->commit();
            $data['ret']='1001';
            $data['code']='success';
            //$data['data']=$data7;
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return true;
        }else{
            //M('lender_distribution','','DB2')->rollback();
            M('vz_loan','','DB2')->rollback();
            M('user','','DB2')->rollback();
            $data['ret']='1002';
            $data['code']='申请失败，请重新提交，';
            //$data['data']=$data7;
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
    }
    /*
     * 首页H5地址接口
     */
    public function index_url(){
        //$get = I('data');
        //$get = $this->jiemi($get);
        $index_url='http://dnqxfv2.hzdouniu.cn/Dev/v2#/CreditLoan';
        $data['ret']='1001';
        $data['code']='success';
        $data['data']=$index_url;
        $data = $this->jiami($data);
        $this->return = ['data'=>$data];
        return true;
    }
    public function jiemimi(){
        $get = I('data');
        $data=$this->jiemi($get);
        print_r($data);
    }
    /*
    * 生成订单号
    */
    public function _getworderno($name)
    {
        nn:
        $order_number = $name . date('Ymd') . time() . rand(10000000, 99999999) . "k";
        switch ($name) {
            case 'J':
                $res = M('vz_loan', null, 'DB2')->where(['order_number' => $order_number])->getField('id');
                break;
            case 'H':
                $res = M('vz_loan', null, 'DB2')->where(['order_number' => $order_number])->getField('id');
                break;
        }
        if ($res) {
            goto nn;
        }
        return $order_number;
    }
    /*
     * 省份地址
     */
    public function BankCard_province(){
        $get = I('data');
        $get = $this->jiemi($get);
        //$get['province_id']=130;
//        if (empty($get['province_id'])){
//            $data['ret']='1002';
//            $data['code']='城市为空';
//            $data = $this->jiami($data);
//            $this->return = ['data'=>$data];
//            return false;
//        }
        $province=M('province','','DB2')->group('province_id')->field('province_name,province_id')->select();
        $data['ret']='1001';
        $data['code']='success';
        $data['is_null']=empty($province)?1:0;//0有数据1没数据
        //$data['page']=count($v2_loan)+$page;
        $data['data']=$province;
        $data = $this->jiami($data);
        $this->return = ['data'=>$data];
        return true;
    }
    /*
     * 地区地址
     */
    public function BankCard_area(){
        $get = I('data');
        $get = $this->jiemi($get);
        //$get['area_id']=1000;
        if (empty($get['province_id'])){
            $data['ret']='1002';
            $data['code']='地区为空';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        $province=M('province','','DB2')->where(['province_id'=>$get['province_id']])->field('area_name,area_id')->select();
        $data['ret']='1001';
        $data['code']='success';
        $data['is_null']=empty($province)?1:0;//0有数据1没数据
        //$data['page']=count($v2_loan)+$page;
        $data['data']=$province;
        $data = $this->jiami($data);
        $this->return = ['data'=>$data];
        return true;
    }
    /*
     * 银行总行
     */
    public function Bank_head_office(){
        $get = I('data');
        $get = $this->jiemi($get);
        //$get['area_id']=1000;
        $total_bank=M('total_bank','','DB2')->field('bank_cd,bank_nm')->select();
        $data['ret']='1001';
        $data['code']='success';
        $data['is_null']=empty($total_bank)?1:0;//0有数据1没数据
        //$data['page']=count($v2_loan)+$page;
        $data['data']=$total_bank;
        $data = $this->jiami($data);
        $this->return = ['data'=>$data];
        return true;
    }
    /*
    * 银行支行
    */
    public function payment_bank(){
        $get = I('data');
        $get = $this->jiemi($get);
        //$get['area_id']=1000;
        //$get['bank_code']='102';
        //$get['city_code']='2900';
        if (empty($get['bank_code'])){
            $data['ret']='1002';
            $data['code']='银行为空';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        if (empty($get['city_code'])){
            $data['ret']='1002';
            $data['code']='城市为空';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        $payment_bank=M('payment_bank','','DB2')->where(['bank_code'=>$get['bank_code'],'city_code'=>$get['city_code']])->field('id,bank_name')->select();
        $data['ret']='1001';
        $data['code']='success';
        $data['is_null']=empty($payment_bank)?1:0;//0有数据1没数据
        //$data['page']=count($v2_loan)+$page;
        $data['data']=$payment_bank;
        $data = $this->jiami($data);
        $this->return = ['data'=>$data];
        return true;
    }
    /*
     * 绑定银行卡
     */
    public function bind_bank()
    {
        $get = I('data');
        $get = $this->jiemi($get);
        //$get['area_id']=1000;
        //$get['bank_code']='102';
        //$get['city_code']='2900';
        if (empty($get['user_id'])){
            $data['ret']='1002';
            $data['code']='请先登录';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }
        if (empty($get['bankcard_id'])){
            $data['ret']='1002';
            $data['code']='银行卡为空';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }
        if (empty($get['bank_name'])){
            $data['ret']='1002';
            $data['code']='银行支行为空';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }
        if(!preg_match("/1[345678]{1}\d{9}$/",$get['mobile'])){
            $data['ret']='1002';
            $data['code']='预留手机号格式不正确';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }
//        if (empty($get['bank_card_type'])){
//            $data['ret']='1002';
//            $data['code']='请选择银行卡类型';
//            $data1 = $this->jiami($data);
//            $this->return = ['data'=>$data1];
//            return false;
//        }
        if (empty($get['jd_bank_code'])){
            $data['ret']='1002';
            $data['code']='银行编码为空';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }
        if (empty($get['shop_identifier'])){
            $data['ret']='1002';
            $data['code']='商户号为空';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }

        $is_data=M('user_bind_bank','','DB2')->where(['user_id'=>$get['user_id'],'status'=>1,'shop_identifier'=>$get['shop_identifier']])->getField('id');
        if($is_data){
            $data['ret']='1002';
            $data['code']='请勿重复绑定';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }
        $data7['user_id']=$get['user_id'];//用户id
        $data7['bankcard_id']=$get['bankcard_id'];//银行卡号
        $data7['bank_name']=$get['bank_name'];//支行名称
        $data7['mobile']=$get['mobile'];//预留手机号
        //$data7['bank_card_type']=$get['bank_card_type'];//1储蓄卡2信用卡
        $data7['jd_bank_code']=$get['jd_bank_code'];//京东支持银行编号
        $data7['shop_identifier']=$get['shop_identifier'];//商户号
        $data7['ctime']=time();
        $data7['utime']=time();
        $user=M('user','','DB2')->where(['id'=>$get['user_id'],'is_delete'=>1])->field('username,identity_num')->find();
        if(empty($user['username'])||empty($user['identity_num'])){
            $data['ret']='1002';
            $data['code']='请先完善个人信息';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }
        M('user_bind_bank','','DB2')->startTrans();
        M('user','','DB2')->startTrans();
        //M('v2_xyc_bank_bind','','DB2_ZX')->startTrans();


//        $url="https://jaqh.56gxxj.com:666/pengyuan/personBank";
//        $data['name']=$user['username'];
//        $data['documentNo']=$user['identity_num'];
//        $data['cardNos']=$get['bankcard_id'];
//        $result = $this->set_curl($url,$data);
//        $result=json_decode($result,true);
//          if($result['isSuccess']==1){
//              $blak_data['user_id']=$get['user_id'];
//              $blak_data['shop_identifier']=$get['shop_identifier'];
//              $blak_data['data']=json_encode($result['data']);
//              $blak_data['ctime']=time();
//              $v2_xyc_bank_bind=M('v2_xyc_bank_bind','','DB2_ZX')->add($blak_data);
//              if(empty($result['data']['personCardTransInfo']['cardInfos'])){
//                  $data7['bank_card_type']=1;//借记卡
//              }else{
//                  $data7['bank_card_type']=2;//信用卡
//              }
//          }else{
//              $data['ret']='1002';
//              $data['code']='银行卡信息获取失败';
//              $data1 = $this->jiami($data);
//              $this->return = ['data'=>$data1];
//              return false;
//          }
        //M('vz_xyc_blak_bind','','DB2_ZX')->add();
        $user_bind_bank=M('user_bind_bank','','DB2')->add($data7);
        $user=M('user','','DB2')->where(['id'=>$get['user_id']])->save(['bankcard_verify'=>3]);
        //if($user_bind_bank&&$user&&$v2_xyc_bank_bind){
        if($user_bind_bank&&$user){
            M('user_bind_bank','','DB2')->commit();
            M('user','','DB2')->commit();
            //M('v2_xyc_bank_bind','','DB2_ZX')->commit();
            $data['ret']='1001';
            $data['code']='success';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return true;
        }else{
            M('user_bind_bank','','DB2')->rollback();
            M('user','','DB2')->rollback();
            //M('v2_xyc_bank_bind','','DB2_ZX')->rollback();
            $data['ret']='1002';
            $data['code']='绑定失败';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }
    }
    /*
     * 支付宝认证
     */
    public function Alipay_bind(){
        $get = I('data');
        $get = $this->jiemi($get);
        if (empty($get['user_id'])){
            $data['ret']='1002';
            $data['code']='请先登录';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        if (empty($get['name'])){
            $data['ret']='1002';
            $data['code']='请输入姓名';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        if (empty($get['account'])){
            $data['ret']='1002';
            $data['code']='请输入支付宝账号';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        $data7['user_id']=$get['user_id'];
        $data7['name']=$get['name'];
        $data7['account']=$get['account'];
        $datsa7['status']=1;
        $data7['ctime']=time();
        $data7['utime']=time();
        $user_alipay_bind=M('user_alipay_bind','','DB2')->add($data7);
        if($user_alipay_bind){
            $data['ret']='1001';
            $data['code']='success';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return true;
        }else{
            $data['ret']='1001';
            $data['code']='绑定失败';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
    }
    /*
     * 京东钱包支持银行
     */
    public function JD_wallet_bank(){
        $jd_bank_info=M('jd_bank_info','','DB2')->field('bank_name,bank_code')->select();
        $data['ret']='1001';
        $data['code']='success';
        $data['is_null']=empty($jd_bank_info)?1:0;
        $data['data']=$jd_bank_info;
        $data = $this->jiami($data);
        $this->return = ['data'=>$data];
        return true;
    }
    /*
     * 自动逾期
     */
    public function automatic_overdue(){
        $time = strtotime(date('Y-m-d'))-1;
        M('vz_bank_ceshi','','DB2')->add(['data'=>'定时任务']);
        $vz_loan=M('vz_loan','','DB2')->where(['status'=>1,'atlast_time'=>['lt',$time]])->field('id')->select();
        foreach ($vz_loan as $key=>$value){
            M('vz_loan','','DB2')->where(['id'=>$value['id']])->save(['status'=>3]);
        }
    }
    /*
     * v2商户后台银行卡报告
     */
    public function v2_bankcard_report(){
        header("Access-Control-Allow-Origin: *");
        $get = I('data');
        $get = $this->jiemi($get);
//        $get['user_id']=23919;
//        $get['shop_identifier']='0100030041';
        if (empty($get['user_id'])){
            $data['ret']='1002';
            $data['code']='请先登录';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            return false;
        }
        if (empty($get['shop_identifier'])){
            $data['ret']='1002';
            $data['code']='商户号为空';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            return false;
        }
        $v2_xyc_bank_bind=M('v2_xyc_bank_bind','','DB2_ZX')->where(['user_id'=>$get['user_id']])->getField('id');
        $py_personbank_checkinfo=M('py_personbank_checkinfo','','DB2_ZX')->where(['user_id'=>$get['user_id']])->getField('id');

        if(empty($v2_xyc_bank_bind)&&empty($py_personbank_checkinfo)) {
            $user=M('user','','DB2')->where(['id'=>$get['user_id']])->field('username,identity_num')->find();
            $user_bind_bank=M('user_bind_bank','','DB2')->where(['user_id'=>$get['user_id']])->field('bankcard_id')->find();
            if(empty($user['username'])||empty($user['identity_num'])||empty($user_bind_bank['bankcard_id'])){
                $data['ret']='1002';
                $data['code']='用户信息不全';
                //$data1 = $this->jiami($data);
                $this->return = ['data'=>$data];
                return false;
            }
            $url = "https://jaqh.56gxxj.com:666/pengyuan/personBank";
            $data['name'] = $user['username'];//姓名
            $data['documentNo'] = $user['identity_num'];//身份证
            $data['cardNos'] = $user_bind_bank['bankcard_id'];//银行卡号
            $data['project'] = 'xyc_v2';//平台标识
            $result = $this->set_curl($url, $data);//请求
            $result = json_decode($result, true);
            if ($result['isSuccess'] == 1) {
                $bank_bind['shop_identifier']=$get['shop_identifier'];
                $bank_bind['data']=json_encode($result['data']);
                $bank_bind['ctime']=time();
                $bank_bind['user_id']=$get['user_id'];
                $v2_xyc_bank_bind=M('v2_xyc_bank_bind','','DB2_ZX')->add($bank_bind);
                $result=$result['data'];
                $res=$result['data'];

                if(!empty($result['personCardTransInfo']['areaExpenseStatis']['domestic'])){
                    foreach ($result['personCardTransInfo']['areaExpenseStatis']['domestic'] as $key=>$value) {
                        $result['personCardTransInfo']['areaExpenseStatis']['domestic'][$key]['type'] = 1;//1国内2境外
                        $result['personCardTransInfo']['areaExpenseStatis']['domestic'][$key]['batNo'] = $result['batNo'];
                        $result['personCardTransInfo']['areaExpenseStatis']['domestic'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['areaExpenseStatis']['domestic'][$key]['ctime'] = time();
                    }
                    M('py_area_expense_statis','','DB2_ZX')->addAll($result['personCardTransInfo']['areaExpenseStatis']['domestic']);//境外消费
                }

                if(!empty($result['personCardTransInfo']['areaExpenseStatis']['intern'])){
                    foreach ($result['personCardTransInfo']['areaExpenseStatis']['intern'] as $key=>$value) {
                        $result['personCardTransInfo']['areaExpenseStatis']['intern'][$key]['type'] = 2;//1国内2境外
                        $result['personCardTransInfo']['areaExpenseStatis']['intern'][$key]['batNo'] = $result['batNo'];
                        $result['personCardTransInfo']['areaExpenseStatis']['intern'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['areaExpenseStatis']['intern'][$key]['ctime'] = time();
                    }
                    M('py_area_expense_statis','','DB2_ZX')->addAll($result['personCardTransInfo']['areaExpenseStatis']['intern']);//境外消费
                }

                $result['personCardTransInfo']['transOverview']['user_id']=$get['user_id'];
                $result['personCardTransInfo']['transOverview']['ctime']=time();
                $result['personCardTransInfo']['transOverview']['onlineTotalExpenseTimes']=$result['personCardTransInfo']['onlineTotalExpenseStatis']['totalExpenseTimes'];
                $result['personCardTransInfo']['transOverview']['onlinePercent']=$result['personCardTransInfo']['onlineTotalExpenseStatis']['percent'];
                $result['personCardTransInfo']['transOverview']['onlineTotalExpense']=$result['personCardTransInfo']['onlineTotalExpenseStatis']['totalExpense'];
                M('py_card_statistics','','DB2_ZX')->add($result['personCardTransInfo']['transOverview']);//银行卡支出



                $data7['user_id']=$get['user_id'];
                $data7['batNo']=$result['batNo'];
                $data7['ctime']=time();
                $data7['percent_00_02']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][0]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][1]['percent'];;
                $data7['percent_02_04']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][2]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][3]['percent'];;
                $data7['percent_04_06']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][4]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][5]['percent'];;
                $data7['percent_06_08']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][6]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][7]['percent'];;
                $data7['percent_08_10']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][8]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][9]['percent'];;
                $data7['percent_10_12']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][10]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][11]['percent'];;
                $data7['percent_12_14']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][12]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][13]['percent'];;
                $data7['percent_14_16']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][14]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][15]['percent'];;
                $data7['percent_16_18']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][16]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][17]['percent'];;
                $data7['percent_18_20']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][18]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][19]['percent'];;
                $data7['percent_20_22']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][20]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][21]['percent'];;
                $data7['percent_22_00']=$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][22]['percent']+$result['personCardTransInfo']['TimeSeriesExpenseTimesStatis'][23]['percent'];;
                M('py_interval_expense_proportion','','DB2_ZX')->add($data7);//所有卡按时间段消费次数统计集合

                foreach ($result['personCardTransInfo']['allCardsCategoryStatis'] as $key=>$value){
                    $result['personCardTransInfo']['allCardsCategoryStatis'][$key]['type']=3;//分析类型1-借记卡2-信用卡3-总详情
                    $result['personCardTransInfo']['allCardsCategoryStatis'][$key]['user_id']=$get['user_id'];
                    $result['personCardTransInfo']['allCardsCategoryStatis'][$key]['ctime']=time();
                    $result['personCardTransInfo']['allCardsCategoryStatis'][$key]['batNo']=$result['batNo'];
                }
                M('py_payment_analyze','','DB2_ZX')->addAll($result['personCardTransInfo']['allCardsCategoryStatis'][$key]);//总卡分析
                if(!empty($result['personCardTransInfo']['allDebitCardsCategoryStatis'])) {
                    foreach ($result['personCardTransInfo']['allDebitCardsCategoryStatis'] as $key => $value) {
                        $result['personCardTransInfo']['allDebitCardsCategoryStatis'][$key]['type'] = 1;//分析类型1-借记卡2-信用卡3-总详情
                        $result['personCardTransInfo']['allDebitCardsCategoryStatis'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['allDebitCardsCategoryStatis'][$key]['ctime'] = time();
                        $result['personCardTransInfo']['allDebitCardsCategoryStatis'][$key]['batNo'] = $result['batNo'];
                    }
                    M('py_payment_analyze','','DB2_ZX')->addAll($result['personCardTransInfo']['allDebitCardsCategoryStatis']);//总卡分析
                }
                if(!empty($result['personCardTransInfo']['allCreditCardsCategoryStatis'])) {
                    foreach ($result['personCardTransInfo']['allCreditCardsCategoryStatis'] as $key => $value) {
                        $result['personCardTransInfo']['allCreditCardsCategoryStatis'][$key]['type'] = 2;//分析类型1-借记卡2-信用卡3-总详情
                        $result['personCardTransInfo']['allCreditCardsCategoryStatis'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['allCreditCardsCategoryStatis'][$key]['ctime'] = time();
                        $result['personCardTransInfo']['allCreditCardsCategoryStatis'][$key]['batNo'] = $result['batNo'];
                    }
                    M('py_payment_analyze', '', 'DB2_ZX')->addAll($result['personCardTransInfo']['allCreditCardsCategoryStatis']);//总卡分析
                }

                if(!empty($result['personCardTransInfo']['allCardsSingleExpenseTop5'])){
                    foreach ($result['personCardTransInfo']['allCardsSingleExpenseTop5'] as $key=>$value){
                        $result['personCardTransInfo']['allCardsSingleExpenseTop5'][$key]['type'] = 1;//1-单笔支出2-线上支出3-大宗商品消费，超过5000人民币的交易
                        $result['personCardTransInfo']['allCardsSingleExpenseTop5'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['allCardsSingleExpenseTop5'][$key]['ctime'] = time();
                        $result['personCardTransInfo']['allCardsSingleExpenseTop5'][$key]['batNo'] = $result['batNo'];
                    }
                    M('py_payment_detail', '', 'DB2_ZX')->addAll($result['personCardTransInfo']['allCardsSingleExpenseTop5']);//单笔支出
                }
                if(!empty($result['personCardTransInfo']['onlineTotalExpenseStatis']['onlineSingleExpenseTop5'])){
                    foreach ($result['personCardTransInfo']['onlineTotalExpenseStatis']['onlineSingleExpenseTop5'] as $key=>$value){
                        $result['personCardTransInfo']['onlineTotalExpenseStatis']['onlineSingleExpenseTop5'][$key]['type'] = 2;//1-单笔支出2-线上支出3-大宗商品消费，超过5000人民币的交易
                        $result['personCardTransInfo']['onlineTotalExpenseStatis']['onlineSingleExpenseTop5'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['onlineTotalExpenseStatis']['onlineSingleExpenseTop5'][$key]['ctime'] = time();
                        $result['personCardTransInfo']['onlineTotalExpenseStatis']['onlineSingleExpenseTop5'][$key]['batNo'] = $result['batNo'];
                    }
                    M('py_payment_detail', '', 'DB2_ZX')->addAll($result['personCardTransInfo']['onlineTotalExpenseStatis']['onlineSingleExpenseTop5']);//线上支出
                }
                if(!empty($result['personCardTransInfo']['BigExpense'])){
                    foreach ($result['personCardTransInfo']['BigExpense'] as $key=>$value){
                        $result['personCardTransInfo']['BigExpense'][$key]['type'] = 3;//1-单笔支出2-线上支出3-大宗商品消费，超过5000人民币的交易
                        $result['personCardTransInfo']['BigExpense'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['BigExpense'][$key]['ctime'] = time();
                        $result['personCardTransInfo']['BigExpense'][$key]['batNo'] = $result['batNo'];
                    }
                    M('py_payment_detail', '', 'DB2_ZX')->addAll($result['personCardTransInfo']['BigExpense']);//大宗消费
                }
                if(!empty($result['personCardTransInfo']['allCreditCards'])) {
                    $result['personCardTransInfo']['allCreditCards']['user_id'] = $get['user_id'];
                    $result['personCardTransInfo']['allCreditCards']['ctime'] = time();
                    $result['personCardTransInfo']['allCreditCards']['batNo'] = $result['batNo'];
                    $result['personCardTransInfo']['allCreditCards']['type'] = 2;//卡类型:1-借记卡2-信用卡
                    M('py_payment_info', '', 'DB2_ZX')->add($result['personCardTransInfo']['allCreditCards']);//信用卡支出提现
                }

                $result['personCardTransInfo']['allDebitCardsExpense']['user_id']=$get['user_id'];
                $result['personCardTransInfo']['allDebitCardsExpense']['ctime']=time();
                $result['personCardTransInfo']['allDebitCardsExpense']['batNo']=$result['batNo'];
                $result['personCardTransInfo']['allDebitCardsExpense']['type']=1;//卡类型:1-借记卡2-信用卡
                M('py_payment_info','','DB2_ZX')->add($result['personCardTransInfo']['allDebitCardsExpense']);//信用卡支出提现
                if(!empty($result['personCardTransInfo']['cardInfos'])) {
                    foreach ($result['personCardTransInfo']['cardInfos'] as $key=>$value) {
                        $result['personCardTransInfo']['cardInfos'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['cardInfos'][$key]['ctime'] = time();
                        $result['personCardTransInfo']['cardInfos'][$key]['batNo'] = $result['batNo'];
                        $result['personCardTransInfo']['cardInfos'][$key]['status'] = $result['personBankCheckInfo'][0]['item']['status'];
                        $result['personCardTransInfo']['cardInfos'][$key]['checkType'] = $result['personBankCheckInfo'][0]['item']['condition']['checkType'];
                        $result['personCardTransInfo']['cardInfos'][$key]['documentNo'] = $result['personBankCheckInfo'][0]['item']['condition']['documentNo'];
                        $result['personCardTransInfo']['cardInfos'][$key]['accountNo'] = $result['personBankCheckInfo'][0]['item']['condition']['accountNo'];
                        $result['personCardTransInfo']['cardInfos'][$key]['name'] = $result['personBankCheckInfo'][0]['item']['condition']['name'];
                        $result['personCardTransInfo']['cardInfos'][$key]['accountBankNo'] = $result['personBankCheckInfo'][0]['item']['condition']['accountBankNo'];
                        $result['personCardTransInfo']['cardInfos'][$key]['accountBankName'] = $result['personBankCheckInfo'][0]['item']['condition']['accountBankName'];
                    }
                    M('py_personbank_checkinfo', '', 'DB2_ZX')->addAll($result['personCardTransInfo']['cardInfos']);
                }
                if(!empty($result['personCardTransInfo']['allCardsMonthTransStatis']['items'])) {
                    foreach ($result['personCardTransInfo']['allCardsMonthTransStatis']['items'] as $key=>$value) {
                        $result['personCardTransInfo']['allCardsMonthTransStatis']['items'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['allCardsMonthTransStatis']['items'][$key]['ctime'] = time();
                        $result['personCardTransInfo']['allCardsMonthTransStatis']['items'][$key]['batNo'] = $result['batNo'];
                    }
                    M('py_personbank_checkinfo', '', 'DB2_ZX')->addAll($result['personCardTransInfo']['allCardsMonthTransStatis']['items']);//卡支出收入月统计
                }
                if(!empty($result['personCardTransInfo']['moreThan2000Statis'])) {
                    foreach ($result['personCardTransInfo']['moreThan2000Statis'] as $key=>$value) {
                        $result['personCardTransInfo']['moreThan2000Statis'][$key]['user_id'] = $get['user_id'];
                        $result['personCardTransInfo']['moreThan2000Statis'][$key]['ctime'] = time();
                        $result['personCardTransInfo']['moreThan2000Statis'][$key]['batNo'] = $result['batNo'];
                    }
                    M('py_personbank_checkinfo', '', 'DB2_ZX')->addAll($result['personCardTransInfo']['moreThan2000Statis']);//卡支出收入月统计
                }
                $result['personCardTransInfo']['allCreditCards']=(object)$result['personCardTransInfo']['allCreditCards'];
                $data['ret']='1001';
                $data['code']='success';
                $data['data']=$result;
                //$data1 = $this->jiami($data);
                $this->return = ['data'=>$data];
                return true;
            } else {
                $data['ret'] = '1002';
                $data['code'] = '银行卡信息获取失败';
                //$data1 = $this->jiami($data);
                $this->return = ['data' => $data];
                return false;
            }
        }else{
            $v2_xyc_bank_bind=M('v2_xyc_bank_bind','','DB2_ZX')->where(['user_id'=>$get['user_id']])->field('data')->find();
            if($v2_xyc_bank_bind){
                $data7=json_decode($v2_xyc_bank_bind['data'],true);
                $data7['personCardTransInfo']['allCreditCards']=(object)$data7['personCardTransInfo']['allCreditCards'];
                $data['ret']='1001';
                $data['code']='success';
                $data['data']=$data7;
                //$data1 = $this->jiami($data);
                $this->return = ['data'=>$data];
                return true;
            }else{
                $data['ret']='1002';
                $data['code']='数据异常';
                //$data1 = $this->jiami($data);
                $this->return = ['data'=>$data];
                return false;
            }
        }

    }
    /*
     * ceshi
     */
    public function ceshi(){

        $numbering ='P20180725200546431452w';///安装包名
//        $numbering = 'P2018153241029445446385w';///安装包名
        $id=13;
        $certificate = M('certificate','',C('DB2'))->alias('a')->join('certificate_period b on a.numbering=b.numbering')->where(['a.numbering'=>$numbering,'b.status'=>'2','b.id'=>$id])->field('a.lender_id,a.borrower_id,a.repayment_time,a.period_time,a.lender_signature,a.borrower_signature,a.ctime,b.period_time')->find();
//        var_dump($certificate);die;
        $lender_data = M('lender','',C('DB2'))->where(['id'=>$certificate['lender_id']])->find();
        $borrower_data = M('user','',C('DB2'))->where(['id'=>$certificate['borrower_id']])->find();
        $user['numbering']=$numbering;
        print_r($lender_data);die;
        $lender_data['name']='林杰接';
        $len = mb_strlen($lender_data['name'], 'UTF-8');
        //echo '中文';
        if($len >= 3){
            //三个字符或三个字符以上掐头取尾，中间用*代替
            $str = mb_substr($lender_data['name'], 0, 1, 'UTF-8') . '*' . mb_substr($lender_data['name'], -1, 1, 'UTF-8');
        } elseif($len == 2) {
            //两个字符
            $str = mb_substr($lender_data['name'], 0, 1, 'UTF-8') . '*';
        }
        echo $str;
//        $loan_amount['loan_amount']=1000;
//        $loan_amount["loan_time"]=1539360000;
//        $interest = (substr(time(), 0, 10) - substr($loan_amount["loan_time"], 0, 10)) / 3600 / 24;///相差天数
//        $interest=round($interest);
//            $Total_interest = (5/10000) * $interest;///天数*日息
//            $Total_interest=$loan_amount['loan_amount']*$Total_interest;//利率*本金
//            $loan_amount['loan_amount'] = round($Total_interest, 2) + $loan_amount['loan_amount'];//本息共计
//        $yanhao1+=$yanhao;
//        $yanhao=1;
//        $yanhao+=2;
        // $interest;die;
        echo $loan_amount['loan_amount'];die;

        $get['shop_identifier']='0100030043';
        print_r($data7['lender_id']=M('lender','','DB2')->where(['shop_idenfier'=>$get['shop_identifier']])->fetchSql(true)->field('id')->find());

    }
    public function dididi(){
        $numbering='P20181027104257709765w';
        $user_id=9173;
        $get["numbering"]='P20181027104257709765w';
        $get['user_id']=9173;
//        $certificate_period = M('certificate_period', Null, 'DB2')->where(["numbering" => $numbering,"borrower_id"=>$user_id])->limit($page, $limit)->field("id,numbering,money,status,period_time")->select();//总数
//        foreach ($certificate_period as $kay => $value) {
//            //$certificate_period[$kay]["repayment_time"]=date('Y-m-d',$value["repayment_time"]);
//            $certificate_period[$kay]["period_time"] = date('Y-m-d', $value["period_time"]);
//        }
//        $data['ret'] = '1001';
//        $data['code'] = 'success';
//        $data['is_null'] = empty($certificate_period) ? 1 : 0;
//        $data['page'] = (string)(count($certificate_period) + $page);
//        $data['data'] = $certificate_period;
//        //$data1 = $this->jiami($data);
//        $this->return = ['data' => $data];
//        return true;
        $user_mob = M('certificate', Null, 'DB2')->where(["numbering" => $get["numbering"], "borrower_id" => $user_id])->field("numbering,loan_time,repayment_time,money,interest_rate,interest,loan_type,status,lender,lender_signature,borrower,borrower_signature,borrower_id,lender,initiate_id")->find();
        switch ($user_mob["loan_type"]) {
            case 1:
                $user_mob["loan_type"] = "日常消费";
                break;
            case 2:
                $user_mob["loan_type"] = "医疗";
                break;
            case 3:
                $user_mob["loan_type"] = "旅游";
                break;
            case 4:
                $user_mob["loan_type"] = "装修";
                break;
            case 5:
                $user_mob["loan_type"] = "教育";
                break;
        }
//        if($user_mob["status"]=["in",2,3,4,9]){
//            $user_mob["status"] = "2";
//        }
        if($user_mob["status"]==9){
            $user_mob["status"] = "2";
        }
        $user_mob["loan_type"] = empty($user_mob["loan_type"]) ? "日常消费" : "日常消费";
        if ($user_mob["borrower_id"] == $user_id) {
            $user_mob["type"] = "1";///1借款人 2出借人
        } else {
            $user_mob["type"] = "2";///1借款人 2出借人
        }
        $user_login = M('user_login', Null, 'DB2')->where(["user_id" => $user_id, "shop_identifier" => $get["shop_identifier"], "status" => 1])->field("paypwd")->find();
        if (!empty($user_login["paypwd"])) {
            $user_mob["is_paypwd"] = "1";///1有支付密码2是没有支付密码
        } else {
            $user_mob["is_paypwd"] = "2";///1有支付密码2是没有支付密码
        }
        $certificate_alipay = M('certificate_alipay', Null, 'DB2')->where(["user_id" => $user_id, "shop_identifier" => $get["shop_identifier"], "status" => 3,"certificate_no"=>$get["numbering"]])->field("id")->find();
        if ($certificate_alipay) {
            $user_mob["is_pay"] = "1";///1已经支付
        } else {
            $user_mob["is_pay"] = "2";///2未支付
        }
        ///测试账号id
//        if($user_id==476){
//            $user_mob["is_pay"] = "1";///已经支付
//        }
//
        //initiate_id
        if ($user_mob["initiate_id"] == $user_id) {
            $user_mob["initiate_type"] = "2";///1可以点击2不能点击
        } else {
            $user_mob["initiate_type"] = "1";///1可以点击2不能点击
        }
        $user_mob["lender_status"] = empty($user_mob["lender_status"]) ? 0 : $user_mob["lender_status"];///借款人状态，1确认借条2发起展期
        $user_mob["borrower_status"] = empty($user_mob["borrower_status"]) ? 0 : $user_mob["borrower_status"];///借款人状态，1确认借款，2确认展期
        $user_mob["lender_avatar"] = '';///出借人头像
        $user_mob["borrower_avatar"] = '';///借款人头像
        $user_mob["service"] = '50';///服务费
        if (strtotime(date('Y-m-d')) < $user_mob["repayment_time"]) {
            $user_mob["overdue"] = 0;///逾期天数
        } else {
            $interest = (strtotime(date('Y-m-d')) - $user_mob["repayment_time"]) / 3600 / 24;///相差天数
            $user_mob["overdue"] = round($interest);///逾期天数
        }
        $user_mob["loan_time"] = date('Y-m-d', $user_mob["loan_time"]);
        $user_mob["repayment_time"] = date('Y-m-d', $user_mob["repayment_time"]);

        if ($user_mob) {
            $data['ret'] = '1001';
            $data['code'] = 'success';
            $data['data'] = $user_mob;
            //$data1 = $this->jiami($data);
            $this->return = ['data' => $data];
            return true;
        } else {
            $data['ret'] = '1002';
            $data['code'] = '凭证错误';
            $data1 = $this->jiami($data);
            $this->return = ['data' => $data1];
            return false;
        }
    }
    public function get_curl($url = '',$data='',$header='')
    {

        $ch = curl_init();
        if (!empty($header)) {
//            $header=array('Content-type: application/json','charset:utf-8'); 示例
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, '1');
        curl_setopt($ch, CURLOPT_URL, $url);
        if (!empty($data)) {
            curl_setopt($ch, CURLOPT_POST, '1');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        //禁用后cURL将终止从服务端进行验证
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $res = curl_exec($ch);
        if (curl_error($ch)) {
            return '错误信息:' . curl_error($ch);
        }
        curl_close($ch);
        return $res;
    }
    /**
     * @param string $url 上传地址
     * @param array $data 上传数组
     * @param string $header 头文件设置
     */
    public function set_curl($url, $data = array(), $header = '')
    {
        $ch = curl_init();
        if (!empty($header)) {
//            $header=array('Content-type: application/json','charset:utf-8'); 示例
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, '1');
        curl_setopt($ch, CURLOPT_URL, $url);
        if (!empty($data)) {
            curl_setopt($ch, CURLOPT_POST, '1');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        //禁用后cURL将终止从服务端进行验证
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $res = curl_exec($ch);
        if (curl_error($ch)) {
            return '错误信息:' . curl_error($ch);
        }
        curl_close($ch);
        return $res;
    }
}